# 对相互之间epoch的距离进行积分
import tool as rd
import os
import numpy as np
import matplotlib.pyplot as plt

#获得积分
def integral(arr):
    res = 0
    for i in arr:
        res = res + i
    return res

root_path1 = 'weights_params/KD/result_15/'
root_path2 = 'weights_params/simple/result_15/'
KD_weights_files = os.listdir(root_path1)
cnn_weights_files = os.listdir(root_path2)

# 记录距离矩阵
KD_dis1 = []
KD_dis2 = []
simple_dis1 = []
simple_dis2 = []

for name in KD_weights_files:
    first_list = rd.read_csv(root_path1 + name)
    list = rd.to_float(first_list)
    arr = np.array(list)
    dis1, dis2 = rd.distance(arr)
    KD_dis1.append(dis1)
    KD_dis2.append(dis2)
    print(name)

for name in cnn_weights_files:
    first_list = rd.read_csv(root_path2 + name)
    list = rd.to_float(first_list)
    arr = np.array(list)
    dis1, dis2 = rd.distance(arr)
    simple_dis1.append(dis1)
    simple_dis2.append(dis2)
    print(name)

KD_dis1_mean = rd.get_mean_arr(np.array(KD_dis1))
KD_dis2_mean = rd.get_mean_arr(np.array(KD_dis2))
simple_dis1_mean = rd.get_mean_arr(np.array(simple_dis1))
simple_dis2_mean = rd.get_mean_arr(np.array(simple_dis2))

y = []
y.append(integral(KD_dis1_mean) / KD_dis2_mean[0])
y.append(integral(simple_dis1_mean)/ simple_dis2_mean[0])
label = ['KD_integral', 'simple_integral']


plt.bar(range(len(y)), y, tick_label=label)
plt.show()